// @algorithm @lc id=100344 lang=cpp
// @title gu-piao-de-zui-da-li-run-lcof

#include "algm/algm.h"
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class Solution {
public:
    int maxProfit(vector<int> &prices) {
        if (prices.empty()) {
            return 0;
        }
        int min_elem = prices[0];
        int ans = 0;
        for (auto &price : prices) {
            min_elem = min(price, min_elem);
            ans = max(price - min_elem, ans);
        }
        return ans;
    }
};